/* 
 * This code is part of the smartlink project, see
 * 
 * 		http://code.google.com/p/smartlink/.
 * 
 * Copyright (C) 2008 Oliver Noelle
 * 
 * SmartLink is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * SmartLink is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with SmartLink.  If not, see <http://www.gnu.org/licenses/>.
 **/
package org.smartlink.search;

/**
 * NgramRep and NgramEntry are needed to represent the searchstring => only
 * created once per search, so we don't worry too much about efficiency/space
 * here
 * 
 * represents a single ngram
 */
class NgramEntry {
	/** count how many times ngram appears */
	public int frequency;
	/** should give an information value to the appearance of this ngram */
	public int entropy;
	/**
	 * index of those ngrams that must be found for this ngram to be
	 * "appearable"
	 */
	public NgramEntry pre1, pre2;
	/** flag for checking precondition */
	public boolean found;
	/** the ngram itself */
	public String ngram;

	// char[] str = new char[FuzzySearch.MAXIMUM_NGRAM_LENGTH + 1];

	/**
	 * one ngram-entry associated with the searchstring keeps track of
	 * frequencies and, corresponding, entropy of an ngram
	 */
	public NgramEntry(String ngram, NgramEntry pre1, NgramEntry pre2) {
		this.ngram = ngram;
		frequency = 0;
		if (ngram.length() == 0) {
			found = true;
			entropy = 20;
		} else {
			found = false;
			entropy = 20 + ngram.length() * 10;
		}
		this.pre1 = pre1;
		this.pre2 = pre2;
	}

	public String toString() {
		return ngram;
	}
};
